package main

import "fmt"

func main() {
	path := []int{}
	fmt.Println(midOrder(&TreeNode{
		Val: 1,
		Left: &TreeNode{
			Val: 2,
		},
		Right: &TreeNode{
			Val: 3,
		},
	}, &path))
	fmt.Println(path)
}

type TreeNode struct {
	Val   int
	Left  *TreeNode
	Right *TreeNode
}

func isValidBST(root *TreeNode) bool {
	return midOrder(root, &[]int{})
}

func midOrder(root *TreeNode, path *[]int) bool {
	if root == nil {
		return true
	}
	ans := midOrder(root.Left, path)
	if len(*path) > 0 && root.Val < (*path)[len(*path)-1] {
		return false
	}
	*path = append(*path, root.Val)
	return ans && midOrder(root.Right, path)
}
